import React, { Component } from 'react'
import styles from "../../assets/styles/ProductList.module.css"

export default class ProductList extends Component {
  addProduct = (pid)=>{
    this.props.getProductId(pid)
  }
  render() {
    const { list } = this.props
    return (
      <div className={styles.list}>
        {list.map(element => {
          return (
            <div key={element.id} className={styles.item}>
              <img width="200px" src={element.imgname} alt="" />
              <p>{element.title}</p>
              <button onClick={()=>this.addProduct(element.id)}>加入购物车</button>
            </div>
          )
        })}
      </div>
    )
  }
}
